package club.xshiwu.springcloud.controller;

import club.xshiwu.springcloud.entities.CommonResult;
import club.xshiwu.springcloud.entities.Payment;
import club.xshiwu.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverport;

    @GetMapping(value = "/payment/create")
    public CommonResult<Payment> create(Payment payment){
        int resoult = paymentService.create(payment);
        if (resoult > 0){
            return new CommonResult(200,"插入成功", payment);
        }else {
            return new CommonResult(444, "插入失败", null);
        }
    }

    @GetMapping(value = "/payment/get/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);

        if (payment != null) {
            return new CommonResult(200, "查询成功: " + payment + "端口为" + serverport);
        } else {
            return new CommonResult(444, "没有对应记录,查询ID: " + id, null);
        }
    }
    @GetMapping(value = "/payment/lb")
    public String getPaymentLB(){
        return serverport;
    }
}
